# -*- coding: utf-8 -*-
'''
@author: olivia.dou
Created on: 9/16/2021 11:30
desc: 针对自动化测试需要撤销审核等情况进行通知
'''

import smtplib,logging
from email.mime.text import MIMEText
from email.header import Header
from base.get_config import get_email_config

def notify(message):
    email_config = get_email_config()
    email_host = email_config['email_host']
    send_user = email_config['send_user']
    password = email_config['password']
    recipient_list = email_config['manual_testers']

    msg = MIMEText(message,'plain','utf-8')

    #msg['Subject'] = Header("%s-%s" % (subject, result_str))
    msg['From'] = send_user
    msg['To'] = ";".join(recipient_list)
    subject = message
    msg['Subject'] = Header(subject, 'utf-8')

    try:
        server = smtplib.SMTP(email_host,25)
        # server.ehlo()
        # server.starttls()
        server.login(send_user,password)

        #smtpObj = smtplib.SMTP('email_host')
        server.sendmail(send_user, recipient_list, msg.as_string())
        #logging.info("邮件发送成功")
    except smtplib.SMTPException:
        logging.error("Error: 无法发送邮件")



 